﻿package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import generalManagerLogic.MockGeneralManagerLogic;


import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import main.Main;

import vo.generalManager.LoginPanelVO;
import vo.generalManager.PromotionPanelVO;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;


public class PromotionPanel extends MyPanel {

	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JLabel jFshareratioLabel;
	private JLabel dJJvalueLabel;
	private JLabel dJJuseratioLabel;
	private JLabel dZJratioLabel;
	private JTextField JFshareratiofield;
	private JTextField DJJvaluefield;
	private JTextField DJJuseratiofield;
	private JTextField DZJratiofieldfield;
	private MyButton sureButton;
	
    protected void initComponent() {
    	PromotionPanelVO ppvo=null;
		try {
			Main.getLogic().toSetPromotion();
			ppvo = Main.getLogic().getPpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
    	
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		this.setBounds(400, 200, 400, 250);
		jFshareratioLabel = new JLabel("销售额与积分兑换比例：  %");
		dJJvalueLabel = new JLabel("等价劵最大使用面额：  /元");
		dJJuseratioLabel = new JLabel("等价劵最大使用比例（每一百销售额）：  /元");
		dZJratioLabel = new JLabel("打折卷最大折扣：  %");
		JFshareratiofield = new JTextField();	
		JFshareratiofield.setText((ppvo.getShareRatio()==null)?"":ppvo.getShareRatio());
		DJJvaluefield = new JTextField();
		DJJvaluefield.setText((ppvo.getMaxEqual()==null)?"":ppvo.getMaxEqual());
		DJJuseratiofield = new JTextField();
		DJJuseratiofield.setText((ppvo.getMaxEqualUse()==null)?"":ppvo.getMaxEqualUse());
		DZJratiofieldfield = new JTextField();
		DZJratiofieldfield.setText((ppvo.getMaxDiscount()==null)?"":ppvo.getMaxDiscount());
		sureButton = new MyButton("确认");
		jFshareratioLabel.setBounds(30, 30, 240, 20);
		dJJvalueLabel.setBounds(30, 60, 240, 20);
		dJJuseratioLabel.setBounds(30, 90, 240, 20);
		dZJratioLabel.setBounds(30, 120, 240, 20);
		JFshareratiofield.setBounds(280, 30	, 60, 25);
		DJJvaluefield.setBounds(280, 60, 60, 25);
		DJJuseratiofield.setBounds(280, 90, 60, 25);
		DZJratiofieldfield.setBounds(280, 120, 60, 30);
		sureButton.setBounds(160, 160, 60, 30);
		this.add(jFshareratioLabel);
		this.add(dJJvalueLabel);
		this.add(dJJuseratioLabel);
		this.add(dZJratioLabel);
		this.add(JFshareratiofield);
		this.add(DJJvaluefield);
		this.add(DJJuseratiofield);
		this.add(DZJratiofieldfield);
		this.add(sureButton);
		
		logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toMain");
		sureButton.setButtonAction("setPromotion");
	}

	@Override
	protected void updateVO() {
		PromotionPanelVO ppvo=null;
		try {
			ppvo = Main.getLogic().getPpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		ppvo.setMaxDiscount(DZJratiofieldfield.getText());
		ppvo.setMaxEqual(DJJvaluefield.getText());
		ppvo.setMaxEqualUse(DJJuseratiofield.getText());
		ppvo.setShareRatio(JFshareratiofield.getText());
		try {
			Main.getLogic().setPpvo(ppvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}


}
